package com.tij.rtti.typeinfo.toys;

/**
 * @ClassName: ToyTest.java
 * @author: xyj
 * @Description: Testing class Class.
 * data:2024/10/6 18:48
 * @since
 **/

interface HasBatteries{}
interface Waterproof{}
interface Shoots{}
interface Wang{}

class Toy {
    Toy(){
        System.out.println("---- Toy()");
    }
    Toy(int i){
        System.out.println("---- Toy(int i)");
    }
}

class FancyToy extends Toy implements HasBatteries,Waterproof,Shoots,Wang{
    FancyToy(){
        super(1);
        System.out.println("---- FancyToy");
    }
}


public class ToyTest {
    static void printInfo(Class cc) {
        System.out.println("Class name " + cc.getName() +
                " is interface ? [" + cc.isInterface() + "] \n" +
                "simple name :" + cc.getSimpleName() + " \n" +
                "Canonical name : "+ cc.getCanonicalName());
        System.out.println("\n ------------ \n");
    }

    public static void main(String[] args) {
        Class c = null;
        try {
            c = Class.forName("com.tij.rtti.typeinfo.toys.FancyToy");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            System.exit(1);
        }

        printInfo(c);

        // get interface
        for(Class face : c.getInterfaces()){
            printInfo(face);
        }
        // get super
        Class up = c.getSuperclass();

        Object obj = null;

        try {
            obj = up.newInstance();
        } catch (InstantiationException e) {
            // 实例化异常
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // 没有足够的权限访问类、方法、成员变量、构造方法
            e.printStackTrace();
        }

        printInfo(obj.getClass());
    }

}
